package com.xzh.exception;

import com.xzh.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//错误提示
@ControllerAdvice("com.xzh.controller")
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody //返回json串
    public Result exception(Exception e) {
        e.printStackTrace();
        return Result.error();
    }
    @ExceptionHandler(CustomException.class)
    @ResponseBody //返回json
    public Result error(CustomException e) {
        return Result.error(e.getCode(), e.getMessage());
    }
}
